﻿/*
____
 L|ypps Web controls for ASP.NET

Copyright (c) 2009 Alessandro Zifiglio, http://www.Typps.com
EMail: alessandro@Typps.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Typps
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.Design;
    using System.Web.UI.Design.WebControls;
    using System.Web.UI.WebControls;

    public class UpdatePanelProgressDesigner : BaseControlDesigner
    {
        #region Fields

        //private DesignerAutoFormatCollection autoFormatsValue = null;
        FormCss form1 = null;
        string[] styles = null;

        #endregion Fields

        #region Methods

        public override string GetDesignTimeHtml()
        {
            UpdatePanelProgress baseComponent = (UpdatePanelProgress)ViewControl;
            string designTimeHtml = base.GetDesignTimeHtml();

            string css = string.Format("<style type=\"text/css\">{0}\r{1}</style>",
                baseComponent.GetCssStyle(), baseComponent.GetSharedCssStyle());
            designTimeHtml = string.Format("{0}{1}", css, designTimeHtml);

            return designTimeHtml;
        }

        protected override void OnRetrieveAutoGeneratedCss(object sender, EventArgs args)
        {
            if (form1 == null)
                form1 = new FormCss(CssSelection.UpdatePanelProgress);

            UpdatePanelProgress baseComponent = (UpdatePanelProgress)ViewControl;

            string updatePanelProgressCss = baseComponent.GetCssStyle(true);
            string sharedCss = baseComponent.GetSharedCssStyle();

            form1.CssSelectedIndexChanged += new CssSelectedIndexChangedEventHandler(form1_CssSelectedIndexChanged);
            form1.WhiteSpaceCheckedChanged += new WhiteSpaceCheckedChangedEventHandler(form1_WhiteSpaceCheckedChanged);
            styles = new string[]
            {
                updatePanelProgressCss,
                sharedCss
            };
            form1.SetCss(string.Join("\r", styles));
            form1.ShowDialog();
        }

        protected override void PreFilterProperties(System.Collections.IDictionary properties)
        {
            base.PreFilterProperties(properties);
        }

        void form1_CssSelectedIndexChanged(object sender, CssSelectedIndexChangedEventArgs e)
        {
            SetCss(e.SelectedIndex, form1.IsWhiteSpaceRemovalChecked());
        }

        void form1_WhiteSpaceCheckedChanged(object sender, WhiteSpaceCheckedChangedEventArgs e)
        {
            SetCss(e.SelectedIndex, e.CheckedStatus);
        }

        void SetCss(CssSelection cs, bool removeWhiteSpace)
        {
            string css = string.Join("\r", styles);
            if (removeWhiteSpace && css != string.Empty)
                css = Helper.TrimWhiteSpace(css);
            form1.SetCss(css);
        }

        #endregion Methods
    }
}